Validate CoinPay CLI payment arguments - #629
Conversation
Greptile SummaryThis PR adds pre-flight validation to the CoinPay CLI target adapter, catching bad arguments (non-positive amounts, blank IDs, malformed asset codes) before the external
Confidence Score: 4/5Safe to merge; the validation logic is correct for all normal inputs and the tests prove the key rejection paths. The validation helpers work correctly and the test suite covers the main paths. The only notable gap is that requireAssetCode uses === undefined for its fallback guard rather than nullish coalescing, so an explicit null coin/fiat bypasses the default and surfaces a misleading required error. packages/targets/payment-coinpay/src/index.ts — specifically the requireAssetCode fallback and the optional blockchain field in the create handler. Important Files Changed
Reviews (1): Last reviewed commit: "Validate CoinPay CLI payment arguments" | Re-trigger Greptile |
| } | ||
|
|
||
| function requireAssetCode(value: unknown, name: string, fallback?: string): string { | ||
| const raw = value === undefined ? fallback : value; |
There was a problem hiding this comment.
The fallback in
requireAssetCode only fires when value === undefined, which means explicitly passing null (a valid unknown value in Record<string, unknown>) bypasses the default and falls through to requireText(null, name), which throws "coin required" instead of using the fallback. The more conventional JavaScript idiom for "treat null and undefined the same" is nullish coalescing, which would correctly apply the fallback for both.
| const raw = value === undefined ? fallback : value; | |
| const raw = value ?? fallback; |
| if (config.args?.blockchain) args.push('--blockchain', String(config.args.blockchain)); | ||
| const amount = requirePositiveAmount(config.args?.amount); | ||
| args.push('--amount', String(amount)); | ||
| if (config.args?.blockchain) args.push('--blockchain', requireAssetCode(config.args.blockchain, 'blockchain')); |
There was a problem hiding this comment.
Missing
blockchain field validation for create — blockchain is optional here but may be required by the CoinPay CLI. If omitted, the CLI invocation goes out without --blockchain and any resulting error surfaces as an opaque CLI failure rather than an early, clear validation message. Consider making the field required for create (or documenting that the CLI has a default).
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
9 similar comments
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
Fixes #628.
Changes:
Validation: